FROM maven:3.8-openjdk-11 AS build

WORKDIR /app

# 复制pom文件
COPY pom.xml .

# 复制源代码
COPY src ./src
COPY libs ./libs

# 构建应用
RUN mvn clean package -Dmaven.test.skip=true

# 运行阶段使用较小的基础镜像
FROM openjdk:11-jre-slim

WORKDIR /app

# 创建必要的目录
RUN mkdir -p /app/logs /app/config /app/heapdump

# 从构建阶段复制jar文件
COPY --from=build /app/target/*.jar /app/app.jar

# 复制配置文件
COPY src/main/resources/application-docker.yml /app/config/application.yml
COPY src/main/resources/logback-spring.xml /app/config/logback-spring.xml

# 暴露端口
EXPOSE 18080
EXPOSE 5060
EXPOSE 5060/udp
EXPOSE 30000-30500/tcp
EXPOSE 30000-30500/udp

# 设置时区
ENV TZ=Asia/Shanghai

# 设置JVM参数
ENV JAVA_OPTS="-Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/app/heapdump/"

# 启动命令
CMD ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar --spring.config.location=/app/config/application.yml"] 